﻿Imports System.Net.Mail
Imports log4net
Imports Equipment.Core

Public Class EmailManager
    Private Shared logger As ILog = LogManager.GetLogger(GetType(EmailManager))

    Private Const UNABLE_TO_SEND_MESSAGE As String = "Unable to send a message: email = {0}. {1}. {2}."

    Public Shared Sub SendEmail(ByVal emailTo As String, ByVal message As String)
        Try
            Dim supportEmail As String = Sys.SupportEmail

            Dim msg As New MailMessage(supportEmail, emailTo)
            msg.Subject = "Equipment Notification."

            msg.Body = message

            Dim smtpClient As ISmtpClient = DependenciesFactory.GetSmtpClient()
            smtpClient.Send(msg)

        Catch ex As Exception
            logger.ErrorFormat(UNABLE_TO_SEND_MESSAGE, emailTo, ex.Message, ex.StackTrace)
        End Try
    End Sub
End Class
